Skip to content

Implement a reversed data transformer for events#4300

Open
integraledelebesgue wants to merge 1 commit into
event-debugging/include-eventsfrom
event-debugging/reverse-transform-events
Open

Implement a reversed data transformer for events#4300
integraledelebesgue wants to merge 1 commit into
event-debugging/include-eventsfrom
event-debugging/reverse-transform-events

Conversation

@integraledelebesgue
Copy link
Copy Markdown
Contributor

Closes #

Introduced changes

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Performed self-review of the code
  • Added changes to CHANGELOG.md

@integraledelebesgue integraledelebesgue requested review from a team, MKowalski8 and franciszekjob and removed request for a team April 22, 2026 09:42
@integraledelebesgue
Copy link
Copy Markdown
Contributor Author

integraledelebesgue commented Apr 22, 2026

@integraledelebesgue integraledelebesgue force-pushed the event-debugging/include-events branch from 8e2f690 to c4c6426 Compare May 7, 2026 12:42
@integraledelebesgue integraledelebesgue requested a review from a team as a code owner May 7, 2026 12:42
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/reverse-transform-events branch 2 times, most recently from fa5bba5 to 3e301c1 Compare May 7, 2026 13:21
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/include-events branch from c4c6426 to ac520db Compare May 7, 2026 21:58
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/reverse-transform-events branch from 3e301c1 to 0a8c413 Compare May 7, 2026 21:58
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/include-events branch from ac520db to 5e31145 Compare May 7, 2026 22:25
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/reverse-transform-events branch from 0a8c413 to d65be70 Compare May 7, 2026 22:28
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/include-events branch from 5e31145 to 47429c0 Compare May 11, 2026 14:05
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/reverse-transform-events branch from d65be70 to 5c111fe Compare May 11, 2026 14:05
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/include-events branch from 47429c0 to ffe000a Compare May 11, 2026 14:18
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/reverse-transform-events branch from 5c111fe to b57024e Compare May 11, 2026 14:18
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/include-events branch from ffe000a to d6ed44a Compare May 11, 2026 14:21
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/reverse-transform-events branch from b57024e to 8fceebe Compare May 11, 2026 14:21
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/include-events branch from d6ed44a to c5d1e90 Compare May 11, 2026 15:09
@integraledelebesgue integraledelebesgue force-pushed the event-debugging/reverse-transform-events branch from 8fceebe to 1256e9c Compare May 11, 2026 15:09
Comment on lines +343 to +374
fn top_level_typed_events(abi: &[AbiEntry]) -> impl Iterator<Item = &TypedAbiEvent> {
// All types ever referenced inside any typed event
let all_types_in_events = abi
.iter()
.filter_map(|entry| match entry {
AbiEntry::Event(AbiEvent::Typed(typed_event)) => Some(typed_event),
_ => None,
})
.flat_map(|typed_event| match typed_event {
TypedAbiEvent::Struct(abi_event_struct) => abi_event_struct
.members
.iter()
.map(|field| field.r#type.as_str())
.collect::<Vec<_>>(),
TypedAbiEvent::Enum(abi_event_enum) => abi_event_enum
.variants
.iter()
.map(|field| field.r#type.as_str())
.collect::<Vec<_>>(),
})
.collect::<Vec<_>>();

// Select only top-level events, i.e. such that are not referenced by other events.
abi.iter().filter_map(move |entry| match entry {
AbiEntry::Event(AbiEvent::Typed(typed_event))
if !all_types_in_events.contains(&typed_event_name(typed_event)) =>
{
Some(typed_event)
}
_ => None,
})
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could we use HashSet instead of a Vec for all_types_in_events? Currently, calling .contains() inside the .filter_map closure gives us O(N^2) complexity, while using HashSet, lookup will decrease to O(1).

self.transform_event_type(&field.r#type, SelectorSource::Consume, db)
}
EventFieldKind::Flat => {
self.transform_event_type(&field.r#type, SelectorSource::None, db)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this still fail for a valid flattened struct field, e.g. OuterEvent { #[flat] inner: InnerEvent, tail: felt252 }? In that case InnerEvent would not have its own selector in the emitted payload, but here we pass SelectorSource::None and the struct path still seems to require one.

Comment on lines +155 to +161
EventFieldKind::Flat => {
if self.event_type_matches_selector(&variant.r#type, selector)? {
return self.transform_event_type(
&variant.r#type,
SelectorSource::Provided(selector),
db,
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be lossy for #[flat] enum variants? It looks like we return only the inner decoded event here, without preserving the outer variant wrapper, which might become ambiguous if multiple flat branches match the same selector.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a regression test for a directly-emitted typed event that is also referenced as a nested payload in another event? That seems like an edge case behind the top-level filtering logic here.

}

/// Transforms a set of event keys and data into a Cairo-like string representation of the event.
pub fn reverse_transform_event(
Copy link
Copy Markdown
Contributor

@franciszekjob franciszekjob May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could we update to ordering so struct/enums are at the top of file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants